/*****************************************************************************
*
*  PROJECT:     SlipStream
*               (Text classes)
*  LICENSE:     GNU General Public License v3 - http://www.gnu.org/licenses/gpl.html

*  DEVELOPERS:  Philip Farquharson <B00137077@studentmail.uws.ac.uk>
*				John Gray <B00145524@studentmail.uws.ac.uk>		
*				Zohaib Bhatti <B00104280@studentmail.uws.ac.uk>
*				Euan Hislop <B00138636@studentmail.uws.ac.uk>
*
*****************************************************************************/
#define _USE_MATH_DEFINES 
#include "CTextObject.h"

CTextObject::CTextObject(CVector2 vecPosition, CColor colText, const char* szInitialText)
{
	m_vecPosition = vecPosition;

	m_szText = new char[strlen(szInitialText) + 1];
	strcpy(m_szText, szInitialText);

	m_colText = colText;
	m_bVisible = true;
}

CTextObject::~CTextObject()
{

}

void CTextObject::Draw(GLuint fontBase)
{
	if ( m_bVisible )
	{
		glLoadIdentity();
		glTranslatef(0.0,0.0,-1.0f);

		glColor4f(m_colText.r, m_colText.g, m_colText.b, m_colText.a);
		glRasterPos2f(m_vecPosition.getX(), m_vecPosition.getY());

		glPushAttrib(GL_LIST_BIT);
		glListBase(fontBase - 32);
		glCallLists((GLsizei)strlen(m_szText), GL_UNSIGNED_BYTE, m_szText);
		glPopAttrib();
	}
}

void CTextObject::setText ( const char* szText, ... )
{
	char buffer[1024];
	va_list args;
	va_start(args, szText);
		vsprintf_s(buffer, 1024, szText, args);
	va_end(args);
	
	delete m_szText;
	m_szText = new char[strlen(buffer) + 1];
	strcpy(m_szText, buffer);
}